const  mongoose =require("mongoose");
const  mongooseConf=require("../../config/db/dbConfig");

let DB_URL = mongooseConf.host;
let DB_PORT = mongooseConf.port;
let DB_BASE = mongooseConf.database;
let DB_USER = mongooseConf.username;
let DB_PWD = mongooseConf.password;
let db=`mongodb://${DB_URL}:${DB_PORT}/${DB_BASE}`;
mongoose.connect(db,{ useNewUrlParser: true ,useUnifiedTopology:true});//本地测试

// let db=`mongodb://${DB_USER}:${DB_PWD}@${DB_URL}:${DB_PORT}/${DB_BASE}`;
// mongoose.connect(db,{ useNewUrlParser: true ,useUnifiedTopology:true,authSource: 'admin'});

//链接数据库成功回调
mongoose.connection.on("connected",()=>{
    console.log("连接数据库成功");
});

//链接数据库失败回调
mongoose.connection.on("err",()=>{
    console.log("连接数据库失败");
});

//断开链接回调
mongoose.connection.on("disconnected",()=>{
    console.log("断开连接");
});

module.exports=mongoose;